﻿using System;
using System.Runtime.Serialization;
using Catel.Articles.Base.Data.Attributes;
using Catel.Data;

namespace Catel.Articles._01___Data_handling.Models
{
    /// <summary>
    /// FirstDataObject Data object class which fully supports serialization, property changed notifications,
    /// backwards compatibility and error checking.
    /// </summary>
    [Example("First data object", "Shows how to create your first data object",
        SourceFileName = "/Models/FirstDataObject.cs")]
    [Serializable]
    public class FirstDataObject : DataObjectBase<FirstDataObject>
    {
        #region Variables
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new object from scratch.
        /// </summary>
        public FirstDataObject() { }

        /// <summary>
        /// Initializes a new object based on <see cref="SerializationInfo"/>.
        /// </summary>
        /// <param name="info"><see cref="SerializationInfo"/> that contains the information.</param>
        /// <param name="context"><see cref="StreamingContext"/>.</param>
        protected FirstDataObject(SerializationInfo info, StreamingContext context)
            : base(info, context) { }
        #endregion
        
        #region Properties
        /// <summary>
        /// Gets or sets the simple property.
        /// </summary>
        public string SimpleProperty
        {
            get { return GetValue<string>(SimplePropertyProperty); }
            set { SetValue(SimplePropertyProperty, value); }
        }

        /// <summary>
        /// Register the SimpleProperty property so it is known in the class.
        /// </summary>
        public static readonly PropertyData SimplePropertyProperty = RegisterProperty("SimpleProperty", typeof(string), "Simple property");

        /// <summary>
        /// Gets or sets the callback property.
        /// </summary>
        public string CallbackProperty
        {
            get { return GetValue<string>(CallbackPropertyProperty); }
            set { SetValue(CallbackPropertyProperty, value); }
        }

        /// <summary>
        /// Register the CallbackProperty property so it is known in the class.
        /// </summary>
        public static readonly PropertyData CallbackPropertyProperty = RegisterProperty("CallbackProperty", typeof(string), "Callback property", (sender, e) => ((FirstDataObject)sender).OnCallbackPropertyChanged());

        /// <summary>
        /// Called when the CallbackProperty property has changed.
        /// </summary>
        private void OnCallbackPropertyChanged()
        {
        }
        #endregion

        #region Methods
        #endregion
    }
}
